package com.example.juc;

import java.util.concurrent.CyclicBarrier;

public class CyclicBarrierDemo {

	public final static int NUMBER = 7;

	public static void main(String[] args) {
		CyclicBarrier cyclicBarrier = new CyclicBarrier(NUMBER, () -> {
			System.out.println("分任务全部完成，开始Running.....");
		});

		for (int i = 1; i <= NUMBER; i++) {
			new Thread(() -> {
				System.out.println(Thread.currentThread().getName() + "任务开始执行。");
				try {
					cyclicBarrier.await();
				} catch (Exception e) {
					e.printStackTrace();
				}
				System.out.println(Thread.currentThread().getName() + " start to happy");
			}, String.valueOf(i)).start();
		}
	}
}
